﻿using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;

namespace Lottery.Client.SL.Controls
{
    public partial class ConfirmBetting : ChildWindow
    {
        private StructBetData _structBetData;
        private EventHandler _eventHandler;
        public IBuyLottery IBuy;
        private bool _bool;

        public event EventHandler BetSucess
        {
            add
            {
                EventHandler eventHandler = this._eventHandler;
                EventHandler eventHandler2;
                do
                {
                    eventHandler2 = eventHandler;
                    EventHandler eventHandler3 = (EventHandler) Delegate.Combine(eventHandler2, value);
                    eventHandler = Interlocked.CompareExchange<EventHandler>(ref this._eventHandler, eventHandler3,
                                                                             eventHandler2);
                } while (eventHandler != eventHandler2);
            }
            remove
            {
                EventHandler eventHandler = this._eventHandler;
                EventHandler eventHandler2;
                do
                {
                    eventHandler2 = eventHandler;
                    EventHandler eventHandler3 = (EventHandler) Delegate.Remove(eventHandler2, value);
                    eventHandler = Interlocked.CompareExchange<EventHandler>(ref this._eventHandler, eventHandler3,
                                                                             eventHandler2);
                } while (eventHandler != eventHandler2);
            }
        }

        public ConfirmBetting()
        {
            this._structBetData = new StructBetData();
            this.InitializeComponent();
            this.btClose.Click += (new RoutedEventHandler(this.btClose_Click));
            this.lbWaiting.Text = ("数据接收中...");
            DataCache.ChildWindowObject = this;
        }

        private void btClose_Click(object obj, RoutedEventArgs routedEventArgs)
        {
            this.OnClose();
        }

        private void OnClose()
        {
            if (this._eventHandler != null)
            {
                this._eventHandler.Invoke(this, null);
            }
            base.DialogResult = new bool?(true);
        }

        private void BetCompleted(object obj, byte[] datas)
        {
            App.ShowMsg("Not Implemented!");
            //App.app_client.BetCompleted -= new ClientControl.RecvDataEventHandler(this.dfG89gp0TU);
            //string text = PublicFunction.ByteToString(datas);
            //if (!string.IsNullOrEmpty(text))
            //{
            //    text = BcZJxKMIDcH0kvSFls.w4WekCpilj(5716) + text;
            //}
            //else
            //{
            //    text = BcZJxKMIDcH0kvSFls.w4WekCpilj(5726);
            //}
            this.lbMsg.Text = "Not Implemented!";
            this.gridLoading.Visibility = Visibility.Collapsed;
            this.gridComplete.Visibility = Visibility.Visible;
            base.Focus();
        }

        private void btnPost_Click(object sender, RoutedEventArgs e)
        {
            this.gridBet.Visibility = Visibility.Collapsed;
            this.gridLoading.Visibility = Visibility.Visible;
            //App.app_client.BetCompleted += new ClientControl.RecvDataEventHandler(this.BetCompleted);
            //App.app_client.InitiateScheme(this._structBetData);
            BetCompleted(this,null);
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.OnClose();
        }

        public void ShowBetMsg(int IsuseID, string IsuseName, int lotteryid, string playid, string typename,
                               int sumInvestNum, double sMultiple, double sumMoney, string betCount)
        {
            this.rnLotteryName.Text=(LotteryInfos.GetLotteryName(DataCache.CurrentPlayInfo.LotteryID));
            this.tbInvestNum.Text=(sumInvestNum.ToString() + "?");
            this.tbMultiple.Text=(sMultiple.ToString() + "?");
            this.tbSumMoney.Text=(sumMoney.ToString() + "?" + DataCache.Units);
            this.tbPlayTypeName.Text=(typename);
            this.gridComplete.Visibility= Visibility.Collapsed;
            this.gridLoading.Visibility = Visibility.Collapsed;
            this.gridBet.Visibility=(0);
            this._structBetData.LotteryID = lotteryid;
            this._structBetData.PlayTypeID = playid;
            this._structBetData.SchemeMultiple = sMultiple;
            this._structBetData.SumMoney = sumMoney;
            this._structBetData.PlayTypeName = typename;
            //\\?
            if (typename.Contains("单式"))
            {
                this._structBetData.LotteryNumber = betCount;
            }
            else
            {
                this._structBetData.LotteryNumber = (betCount);
            }
            base.Show();
        }
    }
}
